package com.zc.service.impl;

import com.zc.mapper.TOrderMapper;
import com.zc.mq.RabbitOrder;
import com.zc.mq.RabbitOrderSender;
import com.zc.pojo.TOrder;
import com.zc.service.BrokerMassageLogService;
import com.zc.service.TOrderService;
import com.zc.utils.JsonUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;

@Service
public class TOrderServiceImpl implements TOrderService {

    @Autowired
    private TOrderMapper tOrderMapper;

    @Autowired
    private RabbitOrderSender rabbitOrderSender;

    @Resource
    private BrokerMassageLogService brokerMassageLogService;


    @Override
    public void creat(String name) {
        String massageId = "MQ_Order_" + UUID.randomUUID().toString();
        TOrder tOrder = new TOrder();
        tOrder.setId(UUID.randomUUID().toString());
        tOrder.setName(name);
        tOrder.setMassageId(massageId);
        tOrderMapper.insert(tOrder);
        RabbitOrder rabbitOrder = new RabbitOrder();
        BeanUtils.copyProperties(tOrder, rabbitOrder);
        //记录发送消息
        rabbitOrderSender.sendSave(rabbitOrder);
        rabbitOrderSender.send(rabbitOrder);


    }
}
